<?php

/**
 * Permission form view.
 *
 * @var \yii\web\View           $this            View
 * @var \yii\widgets\ActiveForm $form            Form
 * @var \yii\base\DynamicModel  $model           Model
 * @var \common\widgets\Box     $box             Box widget instance
 * @var array                   $permissionArray Permissions array
 * @var array                   $ruleArray       Rules array
 */

use common\modules\user\Module;
use common\widgets\Select2;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

?>
<?php $form = ActiveForm::begin(); ?>
<div class="row">
    <div class="col-sm-6">
        <?= $form->field($model, 'name')->label(Module::t('user', 'BACKEND_PERMISSIONS_ATTR_NAME')) ?>
    </div>
    <div class="col-sm-6">
        <?= $form->field($model, 'ruleName')->widget(Select2::className(), [
            'options'       => [
                'prompt' => Module::t('user', 'BACKEND_PERMISSIONS_RULE_NAME_PROMPT'),
            ],
            'pluginOptions' => [
                'width' => '100%',
            ],
            'data'          => $ruleArray,
        ]) ?>
    </div>
</div>
<div class="row">
    <div class="col-sm-6">
        <?= $form->field($model, 'description')->textarea()->label(Module::t('user', 'BACKEND_PERMISSIONS_ATTR_DESCRIPTION')) ?>
    </div>
    <div class="col-sm-6">
        <?= $form->field($model, 'data')->textarea()->label(Module::t('user', 'BACKEND_PERMISSIONS_ATTR_DATA')) ?>
    </div>
</div>
<div class="row">
    <div class="col-sm-12">
        <?= $form->field($model, 'children')->widget(Select2::className(), [
            'options'       => [
                'multiple'    => true,
                'placeholder' => Module::t('user', 'BACKEND_PERMISSIONS_CHILDREN_PROMPT'),
            ],
            'pluginOptions' => [
                'width' => '100%',
            ],
            'data'          => $permissionArray,
        ])->label(Module::t('user', 'BACKEND_PERMISSIONS_ATTR_CHILDREN')) ?>
    </div>
</div>

<?= Html::submitButton(! isset($update) ? Module::t('user', 'BACKEND_PERMISSIONS_CREATE_SUBMIT') : Module::t('user', 'BACKEND_PERMISSIONS_UPDATE_SUBMIT'), [
    'class' => ! isset($update) ? 'btn btn-primary btn-large' : 'btn btn-success btn-large',
]) ?>

<?php ActiveForm::end(); ?>
